RectObjectCreater = class(SimpleObjectCreater)

function RectObjectCreater:init(id,name,tex,icon)
    SimpleObjectCreater.init(self,id,name,tex,icon)
end

-- 此方法设置了普通创建时的长宽
function RectObjectCreater:setSimpleSize(width,height)
    self.simpleWidth = width
    self.simpleHeight = height
    return self
end

-- 设置物体渲染宽度(或相对与创建宽度的偏移)
function RectObjectCreater:setRenderSize(width,height,widthOffset,heightOffset)
    self.renderWidth = width
    self.renderHeight = height
    self.widthOffset = widthOffset
    self.heightOffset = heightOffset
    return self
end

function RectObjectCreater:createBody(x,y,angle,w,h,...)
    w = w or self.simpleWidth
    h = h or self.simpleHeight
    local body = physics.body(POLYGON,vec2(-w/2, h/2),vec2(-w/2, -h/2), vec2(w/2, -h/2), vec2(w/2, h/2))
    self:startCreating(body)
    body.x = x
    body.y = y
    body.width = w
    body.height = h
    body.angle = angle or 0
    body.id = self.id
    body.tex = self.tex
    body.draw = self.draw
    body.interpolate = true
    
    body.renderWidth = self.renderWidth or w + (self.widthOffset or 0)
    body.renderHeight = self.renderHeight or h + (self.heightOffset or 0)
    
    body.renderXOffset = self.renderXOffset
    body.renderYOffset = self.renderYOffset
    
    for k,v in pairs(self.parameter) do
        body[k] = v
    end
    
    self:createFunction(body,...)
    
    return body
end

-- 此方法可能需要重写
function RectObjectCreater:createFunction(body,...)
    
end

function RectObjectCreater:draw()
    pushMatrix()
    translate(self.x, self.y)
    rotate(self.angle)
    sprite(self.tex, self.renderXOffset, self.renderYOffset, self.renderWidth, self.renderHeight)
    popMatrix()
    

end

function RectObjectCreater:touched(touch)
    
end
